using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 工具类
/// </summary>
public class UnityTools
{
    /// <summary>
    /// 重置位置信息
    /// </summary>
    /// <param name="transform"></param>
    public static void ResetTransform(Transform transform)
    {
        transform.localPosition = Vector3.zero;
        transform.localScale = Vector3.one;
        transform.localRotation = Quaternion.identity;

        transform.position = Vector3.zero;
        transform.rotation = Quaternion.identity;
        transform.localScale = Vector3.one;
    }

    /// <summary>
    /// 将json转化为Object
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="json"></param>
    /// <returns></returns>
    public static T ToObject<T>(string json)
    {
        if (StringEmpty(json))
        {
            new Exception("json数据是空的，请检查数据！");
        }
        return LitJson.JsonMapper.ToObject<T>(json);
    }

    /// <summary>
    /// 将Objecet转化为json
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    public static string ToJson(System.Object data)
    {
        if (data==null)
        {
            new Exception("数据为空，请检查数据");
        }
        return LitJson.JsonMapper.ToJson(data);
    }

    /// <summary>
    /// 检查字符串是否为空
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    public static bool StringEmpty(string str)
    {
        return String.IsNullOrEmpty(str);
    }

    /// <summary>
    /// 屏幕坐标转世界坐标
    /// </summary>
    public Vector2 MousePosToWorldPos2D()
    {
        return Camera.main.ScreenToWorldPoint(Input.mousePosition);
    }

    /// <summary>
    /// 屏幕坐标转世界坐标
    /// </summary>
    /// <param name="t"></param>
    /// <returns></returns>
    public Vector3 MousePosToWorldPos3D(Transform t)
    {
        return Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, t.position.z));
    }

}
